package com.lottemall.search.web;

import com.lottemall.common.vo.PageResult;
import com.lottemall.search.pojo.Goods;
import com.lottemall.search.pojo.SearchRequest;
import com.lottemall.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 前端搜索控制器
 * POST http://api.lottemall.com/api/search/page (传入的是Json对象：内含搜索关键字：页码等)
 */
@RestController
public class SearchController {

    /**
     * 搜索业务
     */
    @Autowired
    private SearchService searchService;

    /**
     * 搜索功能
     * @param searchRequest 前端发送的json对象：内含搜索关键字和页码等
     * @return
     */
    @PostMapping("page")
    public ResponseEntity<PageResult<Goods>> search(@RequestBody SearchRequest searchRequest){
        return ResponseEntity.ok(searchService.search(searchRequest));
    }
}
